package evento;


import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import banco.Criptor;
import bean.Estado;

import clienteQuery.Cliente;

import view.ClienteFormJanela;
import view.ClienteJanela;
import view.OperacaoJanela;
import view.PanelCliente;
import view.PrincipalJanela;

import controleCliente.ClienteBO;
import controleCliente.ClienteFormBO;
import erro.Mensagem;

public class EventoCliente {
	public static ClienteBO control;
	private static int acao = ClienteBO.SALVAR_CLIENTE;
	private static Cliente cliente = null;
	
	
	public static void setEventoCliente(PrincipalJanela janela) {
		PanelCliente panel = (PanelCliente)janela.getContentPane().getComponent(1);
		panel.getJButtonAdicionar().addActionListener(new BotaoAdicionarActionListener(panel));
		panel.getJTable().addMouseListener(new CliqueDuploMouseListener(panel));
		
	}
	
	/**
	 * Class para listener Adicionar da Janela Cliente
	 * Estancia a janela ClienteFormJanela
	 * @author shara
	 *
	 */
	private static class BotaoAdicionarActionListener implements ActionListener {
		
		private PanelCliente janela = null;
		
		public BotaoAdicionarActionListener(PanelCliente janela) {
			
			this.janela = janela;
        
		}
		
		public void actionPerformed(ActionEvent evt) {
			ClienteFormBO.getInstance().setClienteForm(new Cliente());
			ClienteFormBO.getInstance().setSelectIndexEstado(5);
			ClienteFormBO.getInstance().criaJanelaForm(); 
		 }
			
	}
	
	private static class CliqueDuploMouseListener extends MouseAdapter {
		
		private PanelCliente janela = null;
		
		public CliqueDuploMouseListener(PanelCliente janela) {
			this.janela = janela;
		}
		
		public void mouseClicked(MouseEvent e) {
			if (e.getClickCount()==2){  
				
				System.out.println("mouseClicked()tabela");


				
				ClienteBO.getInstance().preencheFormParaEdicao(Integer.parseInt( janela.getJTable().getModel().getValueAt(janela.getJTable().getSelectedRow(), 0).toString()));
				
				//System.out.println((String)janela.getJTable().getValueAt(linha_selec, 0));
			}
			
			// TODO Auto-generated Event stub mouseClicked()
		}
	}
	/***************************************************************************************************/
	
	
	
}